home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kstyle.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  12.1 KB  |  345 lines

  1. /*
  2.  * $Id: kstyle.h 465272 2005-09-29 09:47:40Z mueller $
  3.  * 
  4.  * KStyle
  5.  * Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
  6.  * 
  7.  * QWindowsStyle CC_ListView and style images were kindly donated by TrollTech,
  8.  * Copyright (C) 1998-2000 TrollTech AS.
  9.  * 
  10.  * Many thanks to Bradley T. Hughes for the 3 button scrollbar code.
  11.  *
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Library General Public
  14.  * License version 2 as published by the Free Software Foundation.
  15.  *
  16.  * This library is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.  * Library General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU Library General Public License
  22.  * along with this library; see the file COPYING.LIB.  If not, write to
  23.  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24.  * Boston, MA 02110-1301, USA.
  25.  */
  26.  
  27. #ifndef __KSTYLE_H
  28. #define __KSTYLE_H
  29.  
  30. // W A R N I N G
  31. // -------------
  32. // This API is still subject to change.
  33. // I will remove this warning when I feel the API is sufficiently flexible.
  34.  
  35. #include <qcommonstyle.h>
  36.  
  37. #include <kdelibs_export.h>
  38.  
  39. class KPixmap;
  40.  
  41. struct KStylePrivate;
  42. /** 
  43.  * Simplifies and extends the QStyle API to make style coding easier.
  44.  *  
  45.  * The KStyle class provides a simple internal menu transparency engine
  46.  * which attempts to use XRender for accelerated blending where requested,
  47.  * or falls back to fast internal software tinting/blending routines.
  48.  * It also simplifies more complex portions of the QStyle API, such as
  49.  * the PopupMenuItems, ScrollBars and Sliders by providing extra "primitive
  50.  * elements" which are simple to implement by the style writer.
  51.  *
  52.  * @see QStyle::QStyle
  53.  * @see QCommonStyle::QCommonStyle
  54.  * @author Karol Szwed (gallium@kde.org)
  55.  * @version $Id: kstyle.h 465272 2005-09-29 09:47:40Z mueller $
  56.  */
  57. class KDEFX_EXPORT KStyle: public QCommonStyle
  58. {
  59.     Q_OBJECT
  60.  
  61.     public:
  62.  
  63.         /**
  64.          * KStyle Flags:
  65.          * 
  66.          * @li Default - Default style setting, where menu transparency
  67.          * and the FilledFrameWorkaround are disabled.
  68.          * 
  69.          * @li AllowMenuTransparency - Enable this flag to use KStyle's 
  70.          * internal menu transparency engine.
  71.          * 
  72.          * @li FilledFrameWorkaround - Enable this flag to facilitate 
  73.          * proper repaints of QMenuBars and QToolBars when the style chooses 
  74.          * to paint the interior of a QFrame. The style primitives in question 
  75.          * are PE_PanelMenuBar and PE_PanelDockWindow. The HighColor style uses
  76.          * this workaround to enable painting of gradients in menubars and 
  77.          * toolbars.
  78.          */
  79.         typedef uint KStyleFlags;
  80.         enum KStyleOption {
  81.             Default           =        0x00000000, //!< All options disabled
  82.             AllowMenuTransparency =        0x00000001, //!< Internal transparency enabled
  83.             FilledFrameWorkaround =     0x00000002  //!< Filled frames enabled
  84.         };
  85.  
  86.         /**
  87.          * KStyle ScrollBarType:
  88.          *
  89.          * Allows the style writer to easily select what type of scrollbar
  90.          * should be used without having to duplicate large amounts of source
  91.          * code by implementing the complex control CC_ScrollBar.
  92.          *
  93.          * @li WindowsStyleScrollBar - Two button scrollbar with the previous
  94.          * button at the top/left, and the next button at the bottom/right.
  95.          *
  96.          * @li PlatinumStyleScrollBar - Two button scrollbar with both the 
  97.          * previous and next buttons at the bottom/right.
  98.          *
  99.          * @li ThreeButtonScrollBar - %KDE style three button scrollbar with
  100.          * two previous buttons, and one next button. The next button is always
  101.          * at the bottom/right, whilst the two previous buttons are on either 
  102.          * end of the scrollbar.
  103.          *
  104.          * @li NextStyleScrollBar - Similar to the PlatinumStyle scroll bar, but
  105.          * with the buttons grouped on the opposite end of the scrollbar.
  106.          *
  107.          * @see KStyle::KStyle()
  108.          */
  109.         enum KStyleScrollBarType {
  110.             WindowsStyleScrollBar  =     0x00000000, //!< two button, windows style
  111.             PlatinumStyleScrollBar =     0x00000001, //!< two button, platinum style
  112.             ThreeButtonScrollBar   =     0x00000002, //!< three buttons, %KDE style
  113.             NextStyleScrollBar     =     0x00000004  //!< two button, NeXT style
  114.         };
  115.  
  116.         /** 
  117.          * Constructs a KStyle object.
  118.          *
  119.          * Select the appropriate KStyle flags and scrollbar type
  120.          * for your style. The user's style preferences selected in KControl
  121.          * are read by using QSettings and are automatically applied to the style.
  122.          * As a fallback, KStyle paints progressbars and tabbars. It inherits from
  123.          * QCommonStyle for speed, so don't expect much to be implemented. 
  124.          *
  125.          * It is advisable to use a currently implemented style such as the HighColor
  126.          * style as a foundation for any new KStyle, so the limited number of
  127.          * drawing fallbacks should not prove problematic.
  128.          *
  129.          * @param flags the style to be applied
  130.          * @param sbtype the scroll bar type
  131.          * @see KStyle::KStyleFlags
  132.          * @see KStyle::KStyleScrollBarType
  133.          * @author Karol Szwed (gallium@kde.org)
  134.          */
  135.         KStyle( KStyleFlags flags = KStyle::Default, 
  136.             KStyleScrollBarType sbtype = KStyle::WindowsStyleScrollBar );
  137.  
  138.         /** 
  139.          * Destructs the KStyle object.
  140.          */
  141.         ~KStyle();
  142.  
  143.         /**
  144.          * Returns the default widget style depending on color depth.
  145.          */
  146.         static QString defaultStyle();
  147.  
  148.         /**
  149.          * Modifies the scrollbar type used by the style.
  150.          * 
  151.          * This function is only provided for convenience. It allows
  152.          * you to make a late decision about what scrollbar type to use for the
  153.          * style after performing some processing in your style's constructor.
  154.          * In most situations however, setting the scrollbar type via the KStyle
  155.          * constructor should suffice.
  156.          * @param sbtype the scroll bar type
  157.          * @see KStyle::KStyleScrollBarType
  158.          */
  159.         void setScrollBarType(KStyleScrollBarType sbtype);
  160.  
  161.         /**
  162.          * Returns the KStyle flags used to initialize the style.
  163.          *
  164.          * This is used solely for the kcmstyle module, and hence is internal.
  165.          */
  166.         KStyleFlags styleFlags() const;
  167.  
  168.         // ---------------------------------------------------------------------------
  169.  
  170.         /**
  171.          * This virtual function defines the pixmap used to blend between the popup
  172.          * menu and the background to create different menu transparency effects.
  173.          * For example, you can fill the pixmap "pix" with a gradient based on the
  174.          * popup's colorGroup, a texture, or some other fancy painting routine.
  175.          * KStyle will then internally blend this pixmap with a snapshot of the
  176.          * background behind the popupMenu to create the illusion of transparency.
  177.          * 
  178.          * This virtual is never called if XRender/Software blending is disabled by
  179.          * the user in KDE's style control module.
  180.          */
  181.         virtual void renderMenuBlendPixmap( KPixmap& pix, const QColorGroup& cg, 
  182.                             const QPopupMenu* popup ) const;
  183.  
  184.         /**
  185.          * KStyle Primitive Elements:
  186.          *
  187.          * The KStyle class extends the Qt's Style API by providing certain 
  188.          * simplifications for parts of QStyle. To do this, the KStylePrimitive
  189.          * elements were defined, which are very similar to Qt's PrimitiveElement.
  190.          * 
  191.          * The first three Handle primitives simplify and extend PE_DockWindowHandle, 
  192.          * so do not reimplement PE_DockWindowHandle if you want the KStyle handle 
  193.          * simplifications to be operable. Similarly do not reimplement CC_Slider,
  194.          * SC_SliderGroove and SC_SliderHandle when using the KStyle slider
  195.          * primitives. KStyle automatically double-buffers slider painting
  196.          * when they are drawn via these KStyle primitives to avoid flicker.
  197.          *
  198.          * @li KPE_DockWindowHandle - This primitive is already implemented in KStyle,
  199.          * and paints a bevelled rect with the DockWindow caption text. Re-implement
  200.          * this primitive to perform other more fancy effects when drawing the dock window
  201.          * handle.
  202.          *
  203.          * @li KPE_ToolBarHandle - This primitive must be reimplemented. It currently
  204.          * only paints a filled rectangle as default behavior. This primitive is used
  205.          * to render QToolBar handles.
  206.          *
  207.          * @li KPE_GeneralHandle - This primitive must be reimplemented. It is used
  208.          * to render general handles that are not part of a QToolBar or QDockWindow, such
  209.          * as the applet handles used in Kicker. The default implementation paints a filled
  210.          * rect of arbitrary color.
  211.          *
  212.          * @li KPE_SliderGroove - This primitive must be reimplemented. It is used to 
  213.          * paint the slider groove. The default implementation paints a filled rect of
  214.          * arbitrary color.
  215.          *
  216.          * @li KPE_SliderHandle - This primitive must be reimplemented. It is used to
  217.          * paint the slider handle. The default implementation paints a filled rect of
  218.          * arbitrary color.
  219.          *
  220.          * @li KPE_ListViewExpander - This primitive is already implemented in KStyle. It
  221.          * is used to draw the Expand/Collapse element in QListViews. To indicate the 
  222.          * expanded state, the style flags are set to Style_Off, while Style_On implies collapsed.
  223.          *
  224.          * @li KPE_ListViewBranch - This primitive is already implemented in KStyle. It is
  225.          * used to draw the ListView branches where necessary.
  226.          */
  227.         enum KStylePrimitive {
  228.             KPE_DockWindowHandle,
  229.             KPE_ToolBarHandle,
  230.             KPE_GeneralHandle,
  231.  
  232.             KPE_SliderGroove,
  233.             KPE_SliderHandle,
  234.  
  235.             KPE_ListViewExpander,
  236.             KPE_ListViewBranch
  237.         };
  238.  
  239.         /**
  240.          * This function is identical to Qt's QStyle::drawPrimitive(), except that 
  241.          * it adds one further parameter, 'widget', that can be used to determine 
  242.          * the widget state of the KStylePrimitive in question.
  243.          *
  244.          * @see KStyle::KStylePrimitive
  245.          * @see QStyle::drawPrimitive
  246.          * @see QStyle::drawComplexControl
  247.          */
  248.         virtual void drawKStylePrimitive( KStylePrimitive kpe,
  249.                     QPainter* p,
  250.                     const QWidget* widget,
  251.                     const QRect &r,
  252.                     const QColorGroup &cg,
  253.                     SFlags flags = Style_Default,
  254.                     const QStyleOption& = QStyleOption::Default ) const;
  255.  
  256.  
  257.         enum KStylePixelMetric {
  258.             KPM_MenuItemSeparatorHeight        = 0x00000001,
  259.             KPM_MenuItemHMargin            = 0x00000002,
  260.             KPM_MenuItemVMargin            = 0x00000004,
  261.             KPM_MenuItemHFrame            = 0x00000008,
  262.             KPM_MenuItemVFrame            = 0x00000010,
  263.             KPM_MenuItemCheckMarkHMargin            = 0x00000020,
  264.             KPM_MenuItemArrowHMargin        = 0x00000040,
  265.             KPM_MenuItemTabSpacing            = 0x00000080,
  266.             KPM_ListViewBranchThickness        = 0x00000100
  267.         };
  268.  
  269.         int kPixelMetric( KStylePixelMetric kpm, const QWidget* widget = 0 ) const;
  270.  
  271.         // ---------------------------------------------------------------------------
  272.  
  273.         void polish( QWidget* widget );
  274.         void unPolish( QWidget* widget );
  275.         void polishPopupMenu( QPopupMenu* );
  276.  
  277.         void drawPrimitive( PrimitiveElement pe,
  278.                     QPainter* p,
  279.                     const QRect &r,
  280.                     const QColorGroup &cg,
  281.                     SFlags flags = Style_Default,
  282.                     const QStyleOption& = QStyleOption::Default ) const;
  283.  
  284.         void drawControl( ControlElement element,
  285.                     QPainter* p,
  286.                     const QWidget* widget,
  287.                     const QRect &r,
  288.                     const QColorGroup &cg,
  289.                     SFlags flags = Style_Default,
  290.                     const QStyleOption& = QStyleOption::Default ) const;
  291.  
  292.         void drawComplexControl( ComplexControl control,
  293.                     QPainter *p,
  294.                     const QWidget* widget,
  295.                     const QRect &r,
  296.                     const QColorGroup &cg,
  297.                     SFlags flags = Style_Default,
  298.                     SCFlags controls = SC_All,
  299.                     SCFlags active = SC_None,
  300.                     const QStyleOption& = QStyleOption::Default ) const;
  301.  
  302.         SubControl querySubControl( ComplexControl control,
  303.                     const QWidget* widget,
  304.                     const QPoint &pos,
  305.                     const QStyleOption& = QStyleOption::Default ) const;
  306.  
  307.         QRect querySubControlMetrics( ComplexControl control,
  308.                     const QWidget* widget,
  309.                     SubControl sc,
  310.                     const QStyleOption& = QStyleOption::Default ) const;
  311.  
  312.         int pixelMetric( PixelMetric m, 
  313.                     const QWidget* widget = 0 ) const;
  314.  
  315.         QRect subRect( SubRect r, 
  316.                     const QWidget* widget ) const;
  317.  
  318.         QPixmap stylePixmap( StylePixmap stylepixmap,
  319.                     const QWidget* widget = 0,
  320.                     const QStyleOption& = QStyleOption::Default ) const;
  321.  
  322.         int styleHint( StyleHint sh, 
  323.                     const QWidget* w = 0,
  324.                     const QStyleOption &opt = QStyleOption::Default,
  325.                     QStyleHintReturn* shr = 0 ) const;
  326.  
  327.     protected:
  328.         bool eventFilter( QObject* object, QEvent* event );
  329.  
  330.     private:
  331.         // Disable copy constructor and = operator
  332.         KStyle( const KStyle & );
  333.         KStyle& operator=( const KStyle & );
  334.  
  335.     protected:
  336.         virtual void virtual_hook( int id, void* data );
  337.     private:
  338.         KStylePrivate *d;
  339. };
  340.  
  341.  
  342. // vim: set noet ts=4 sw=4:
  343. #endif
  344.  
  345.